// createRouter：创建router实例对象
// createWebHistory：创建history模式的路由

import { createRouter, createWebHistory } from "vue-router";

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    // path和component对应关系的位置
    routes: [
        {
            path: "/login",
            name: "login",
            component: () => import("@/views/Login/index.vue"),
        },
        {
            path: "/",
            name: "layout",
            component: () => import("@/views/Layout/index.vue"),
            children: [
                {
                    path: "",
                    name: "home",
                    component: () => import("@/views/Home/index.vue"),
                },
                {
                    path: "category/:id",
                    name: "category",
                    component: () => import("@/views/Category/index.vue"),
                },
                {
                    path: "category/sub/:id",
                    name: "subCategory",
                    component: () => import("@/views/SubCategory/index.vue"),
                },
                {
                    path: "detail/:id",
                    name: "detail",
                    component: () => import("@/views/Detail/index.vue"),
                },
                {
                    path: "cartlist",
                    name: "cartlist",
                    component: () => import("@/views/CartList/index.vue"),
                },
                {
                    path: "checkout",
                    name: "checkout",
                    component: () => import("@/views/Checkout/index.vue"),
                },
                {
                    path: "pay",
                    name: "pay",
                    component: () => import("@/views/Pay/index.vue"),
                },
                {
                    path: "paycallback",
                    name: "paycallback",
                    component: () => import("@/views/Pay/PayBack.vue"),
                },
                {
                    path: "member",
                    name: "member",
                    component: () => import("@/views/Member/index.vue"),
                    children: [
                        {
                            path: "",
                            name: "default",
                            redirect: { name: "user" },
                        },
                        {
                            path: "user",
                            name: "user",
                            component: () =>
                                import(
                                    "@/views/Member/components/UserInfo.vue"
                                ),
                        },
                        {
                            path: "order",
                            name: "order",
                            component: () =>
                                import(
                                    "@/views/Member/components/UserOrder.vue"
                                ),
                        },
                    ],
                },
            ],
        },
    ],
    // 路由滚动行为定制
    scrollBehavior() {
        return {
            top: 0,
        };
    },
});

export default router;
